//
//  OrderSegmentViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/27.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "ProOrderCenterViewController.h"
#import "SerOrderCenterViewController.h"
#import "FieldOrderCenterViewController.h"

#import "PortfilioSubViewController.h"

#import "OrderSegmentViewController.h"

@interface OrderSegmentViewController ()<XLPageViewControllerDelegate,XLPageViewControllerDataSrouce>

@property (nonatomic, strong) XLPageViewController *pageViewController;

@end

@implementation OrderSegmentViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];
}

- (void)initView {

    self.title = @"订单";
    self.view.backgroundColor = UIColorHex(0xffffff);
    
    self.navigationController.navigationBarHidden = YES;
    #if RT_INTERACTIVE_PUSH
        self.rt_navigationController.rt_enableInteractivePush = YES;
    #endif
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"public_back_black"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    
    [self initPageViewController];
    
    self.pageViewController.selectedIndex = self.selectIndex;

    [self.view addSubview:btn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(kStatusBarHeight);
        make.left.mas_equalTo(0);
        make.height.mas_equalTo(NavBar_Height);
        make.width.mas_equalTo(60);
    }];

}

- (void)goBack {
    
    [[TT_TabbarViewController shareTabbar] setCurrentIndex:TT_TabbarIndexType_Mine];
    [self.navigationController popToRootViewControllerAnimated:NO];
}

- (void)initPageViewController {
    
    XLPageViewControllerConfig *config = [XLPageViewControllerConfig defaultConfig];
    config.shadowLineColor = UIColorHex(0xff4242);
    config.titleSelectedFont = [UIFont boldSystemFontOfSize:16];
    config.titleNormalFont = [UIFont systemFontOfSize:16];
    config.titleViewAlignment = XLPageTitleViewAlignmentCenter;
    config.showTitleInNavigationBar = false;
    config.separatorLineHidden = true;
    config.shadowLineAnimationType = XLPageShadowLineAnimationTypeZoom;
    config.shadowLineWidth = 20;
    
    self.pageViewController = [[XLPageViewController alloc] initWithConfig:config];

    self.pageViewController.delegate = self;
    self.pageViewController.dataSource = self;
    [self addChildViewController:self.pageViewController];
    [self.view addSubview:self.pageViewController.view];
    
    [self.pageViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(kStatusBarHeight);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
//        make.height.mas_equalTo(NavBar_Height);
    }];
}

#pragma mark -
#pragma mark TableViewDelegate&DataSource
- (UIViewController *)pageViewController:(XLPageViewController *)pageViewController viewControllerForIndex:(NSInteger)index {

    if (index == 0) {
        
        SerOrderCenterViewController *vc = [[SerOrderCenterViewController alloc] init];
        vc.titles = @[@"全部",@"待付款",@"待接单",@"待服务",@"待评价"];
        XLPageViewControllerConfig *config = [XLPageViewControllerConfig defaultConfig];
        config.shadowLineColor = UIColorHex(0xff4242);
        config.titleSelectedFont = [UIFont boldSystemFontOfSize:14];
        config.titleNormalFont = [UIFont systemFontOfSize:14];
        config.titleViewAlignment = XLPageTitleViewAlignmentCenter;
        config.separatorLineHidden = true;
        config.shadowLineAnimationType = XLPageShadowLineAnimationTypeZoom;
        config.shadowLineWidth = 20;
        config.titleSpace = 0;
        config.titleWidth = TTScreenWidth/6;
        vc.config = config;

        return vc;
        
    } else if (index == 1) {
        
        ProOrderCenterViewController *vc = [[ProOrderCenterViewController alloc] init];
        vc.titles = @[@"全部",@"待付款",@"待发货",@"待收货",@"待评价"];
        XLPageViewControllerConfig *config = [XLPageViewControllerConfig defaultConfig];
        config.shadowLineColor = UIColorHex(0xff4242);
        config.titleSelectedFont = [UIFont boldSystemFontOfSize:14];
        config.titleNormalFont = [UIFont systemFontOfSize:14];
        config.titleViewAlignment = XLPageTitleViewAlignmentCenter;
        config.separatorLineHidden = true;
        config.shadowLineAnimationType = XLPageShadowLineAnimationTypeZoom;
        config.shadowLineWidth = 20;
        config.titleSpace = 0;
        config.titleWidth = TTScreenWidth/6;
        vc.config = config;

        return vc;
        
    } else {
        
        FieldOrderCenterViewController *vc = [[FieldOrderCenterViewController alloc] init];
        vc.titles = @[@"全部",@"待付款",@"待评价"];
        XLPageViewControllerConfig *config = [XLPageViewControllerConfig defaultConfig];
        config.shadowLineColor = UIColorHex(0xff4242);
        config.titleSelectedFont = [UIFont boldSystemFontOfSize:14];
        config.titleNormalFont = [UIFont systemFontOfSize:14];
        config.titleViewAlignment = XLPageTitleViewAlignmentCenter;
        config.separatorLineHidden = true;
        config.shadowLineAnimationType = XLPageShadowLineAnimationTypeZoom;
        config.shadowLineWidth = 20;
        config.titleSpace = 0;
        config.titleWidth = TTScreenWidth/6;
        vc.config = config;

        return vc;
    }
}

- (NSString *)pageViewController:(XLPageViewController *)pageViewController titleForIndex:(NSInteger)index {
    return [self titles][index];
}

- (NSInteger)pageViewControllerNumberOfPage {
    return [self titles].count;
}

- (void)pageViewController:(XLPageViewController *)pageViewController didSelectedAtIndex:(NSInteger)index {
    NSLog(@"切换到了：%@",[self titles][index]);
}

#pragma mark -
#pragma mark 标题数据
- (NSArray *)titles {
    return @[@"服务",@"婚品",@"酒店"];
}

@end
